package com.example.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/auth")
@Validated
@Slf4j
public class AdminAuthController {

	/**
	 * 管理员 登录接口
	 * @param body
	 * @return
	 */
	@PostMapping("/login")
	public Object login(@RequestBody String body) {
		log.info("【请求开始】系统管理->用户登录,请求参数:body:{}", body);

		Subject currentUser = SecurityUtils.getSubject();
		try {
			currentUser.login(new UsernamePasswordToken("username", "password"));
		} catch (UnknownAccountException uae) {
			return null;
		} catch (LockedAccountException lae) {
			return null;
		} catch (AuthenticationException ae) {
			return null;
		}

		log.info("【请求结束】系统管理->用户登录");

		return null;
	}
}
